/**
 * 
 */
package edu.sjtu.seda.main;

import java.util.concurrent.TimeUnit;

import edu.sjtu.seda.stage.Stage;
import edu.sjtu.seda.stage.StageConfigImpl;
import edu.sjtu.seda.test.Message;
import edu.sjtu.seda.test.PrintMessage;
import edu.sjtu.seda.test.TransferMessage;
import edu.sjtu.seda.test.WriteToFile;

/**
 * @author john.zhu
 *
 */
public class BootStrap {
	
	public void init(){
	}
	
	
	public static void main(String[] args) {
		StagePlatform stages = new StagePlatform();
		Stage st1 = stages.buildStage("stage1", new WriteToFile(),new StageConfigImpl("configuration1.properties"));
		Stage st2 = stages.buildStage("stage2", new PrintMessage(),new StageConfigImpl("configuration2.properties"));
		Stage st3 = stages.buildStage("stage3", new TransferMessage(),new StageConfigImpl("configuration3.properties"));
		stages.start();
		for (int i = 0; i < 100; i++) {
			if(i%2==0){
				Message m = new Message("Message "+i);
				m.pushLocation(stages.getStage("stage2"));
				m.pushLocation(stages.getStage("stage1"));
				stages.pushEvent(m);
			}
			else{
				Message m = new Message("Message "+i);
				m.pushLocation(stages.getStage("stage3"));
				m.pushLocation(stages.getStage("stage1"));
				stages.pushEvent(m);
			}
		}
		try {
			TimeUnit.MILLISECONDS.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		stages.destroy();
	}

}
